namespace NUnitTests{
    using System;
    using System.Threading;
    using System.Windows.Automation;
    using System.Windows.Threading;
    using Guia.Core;
    using Guia.Elements;
    using NUnit.Framework;
    using WpfTestApplication;

    /// <summary>
    ///This is a test class for UIElementTest and is intended
    ///to contain all UIElementTest Unit Tests
    ///</summary>
    [TestFixture]
    public class ApplicationTest
    {
        private Application application;


        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        [SetUp()]
        public void MyTestInitialize()
        {
            //Delay.ForMilliseconds(1000);
        }
        //
        //Use TestCleanup to run code after each test has run
        [TearDown()]
        public void MyTestCleanup()
        {
            //Delay.ForMilliseconds(500);
            if (application != null)
            {
                application.Stop();
            }
            //Delay.ForMilliseconds(500);
        }
        //
        #endregion

        [Test]
        public void TestStartExe()
        {
            this.application = Application.Start(@"WpfTestApplication.exe");
            Assert.IsNotNull(application);
        }

        [Test]
        public void TestStartExeWithParam()
        {
            this.application = Application.Start(@"WpfTestApplication.exe ApplicationTestWindow");
            Assert.IsNotNull(application);
        }

        [Test]
        public void TestGetWindowFromStartExe()
        {
            this.application = Application.Start(@"WpfTestApplication.exe");
            Assert.IsNotNull(application);
            Window w1 = application.GetWindowById("WindowWpfTestApplication");
            Assert.IsNotNull(w1);
            Window w2 = application.GetWindowByName("WpfTestApplication Window");
            Assert.IsNotNull(w2);
        }

        [Test,ExpectedException(typeof(ArgumentException))]
        public void TestGetWindowByIdWithNullValue()
        {
            this.application = Application.Start(@"WpfTestApplication.exe");
            Assert.IsNotNull(application);
            application.GetWindowById(null);
        }

        [Test, ExpectedException(typeof(ArgumentException))]
        public void TestGetWindowByIdWithEmptyValue()
        {
            this.application = Application.Start(@"WpfTestApplication.exe");
            Assert.IsNotNull(application);
            application.GetWindowById("");
        }

        [Test, ExpectedException(typeof(ArgumentException))]
        public void TestGetWindowByNameWithNullValue()
        {
            this.application = Application.Start(@"WpfTestApplication.exe");
            Assert.IsNotNull(application);
            application.GetWindowByName(null);
        }

        [Test, ExpectedException(typeof(ArgumentException))]
        public void TestGetWindowByNameWithEmptyValue()
        {
            this.application = Application.Start(@"WpfTestApplication.exe");
            Assert.IsNotNull(application);
            application.GetWindowByName("");
        }

        [Test]
        public void TestGetWindowFromStartExeWithParam()
        {
            this.application = Application.Start(@"WpfTestApplication.exe ApplicationTestWindow");
            Assert.IsNotNull(application);
            Window w1 = application.GetWindowById("WindowWpfTestApplication");
            Assert.IsNotNull(w1);
            Window w2 = application.GetWindowByName("WpfTestApplication Window");
            Assert.IsNotNull(w2);
        }

        [Test, ExpectedException(typeof(ArgumentException))]
        public void TestStartExeWithNullValue()
        {
            this.application = Application.Start(null);
        }

        [Test, ExpectedException(typeof(ArgumentException))]
        public void TestStartExeWithEmptyValue()
        {
            this.application = Application.Start("");
        }

        [Test, ExpectedException(typeof(ArgumentException))]
        public void TestStartExeWithInexistentFile()
        {
            this.application = Application.Start(@"Z:\This\File\shouldnt\exist.exe");
        }
    }
}
